package com.bmt.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mickyfeng on 14-1-10.
 */
public class StringUtils {
    public static boolean checkNotNullAndEmpty(String value) {
        return !(value == null || "".equals(value));
    }

    public static boolean checkNotNullAndSizeNotZero(ArrayList<Object> ob) {
        return !(ob == null || ob.size() <= 0);
    }

    public static boolean checkNotNullAndSizeNotZero(String[] ob) {
        return !(ob == null || ob.length <= 0);
    }

    public static String inSqlCondition(String[] ob) {
        String str = "''";
        if (checkNotNullAndSizeNotZero(ob)) {
            str = "'" + ob[0] + "'";
            for (int i = 1; i < ob.length; i++) {
                str += ",'" + ob[i] + "'";
            }
        }
        return str;
    }

    public static String inSqlConditionNoQuotationMark(String[] ob) {
        String str = "";
        if (checkNotNullAndSizeNotZero(ob)) {
            str = ob[0];
            for (int i = 1; i < ob.length; i++) {
                str += "," + ob[i];
            }
        }
        return str;
    }

    public static String listToStrings(List<String> list) {
        String str = "''";
        if (list != null && list.size() > 0) {
            str = "'" + list.get(0) + "'";
            for (int i = 1; i < list.size(); i++) {
                str += ",'" + list.get(i) + "'";
            }
        }
        return str;
    }

    public static String listToStringsNoQuotation(List<String> list) {
        String str = "";
        if (list != null && list.size() > 0) {
            str = list.get(0);
            for (int i = 1; i < list.size(); i++) {
                str += "," + list.get(i);
            }
        }
        return str;
    }

    public static boolean inList(List<String> list, String str) {
        if (str == null)
            return false;
        if (list != null) {
            for (int index = 0; index < list.size(); index++)
                if (str.equals(list.get(index)))
                    return true;
        }
        return false;
    }
}
